//-----------------------------------------------------------------------------
// File: VirtualPropertyDescriptor.cs
//
// Copyright (c) Dmitry Shuklin. All rights reserved.
//-----------------------------------------------------------------------------
using System;

namespace ObjectiveDraw.Platform.Serialization
{
	/// <summary>
	/// Summary description for VirtualPropertyDescriptor.
	/// </summary>
	public class VirtualPropertyDescriptor : System.ComponentModel.PropertyDescriptor 
	{
		public VirtualPropertyDescriptor(string attributeName, System.Attribute [] attributes) : base(attributeName, attributes)
		{
			//
			// TODO: Add constructor logic here
			//
		}

		public override bool CanResetValue(object component)
		{
			return false;
		}

		public override object GetValue(object component)
		{
			ObjectiveDraw.Platform.Serialization.ISerializable ser = component as ObjectiveDraw.Platform.Serialization.ISerializable;
			if(ser!=null)
			{
				return ser.GetValue(this.Name);
			}
			return null;
		}

		public override bool IsReadOnly
		{
			get
			{
				return false;
			}
		}

		public override void ResetValue(object component)
		{

		}

		public override void SetValue(object component, object value)
		{
			ObjectiveDraw.Platform.Serialization.ISerializable ser = component as ObjectiveDraw.Platform.Serialization.ISerializable;
			if(ser!=null)
			{
				ser.SetValue(this.Name, true, value);
			}
		}

		public override bool ShouldSerializeValue(object component)
		{
			return false;
		}

		public override Type PropertyType
		{
			get
			{
				return typeof(System.Object);
			}
		}

		public override Type ComponentType
		{
			get
			{
				return typeof(System.Object);
			}
		}

	}
}
